<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改活动')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-huoDong-edit" th:object="${jiajiaHuoDong}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label">活动名称：</label>
                <div class="col-sm-8">
                    <input name="name" th:field="*{name}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">展示端：</label>
                <div class="col-sm-8">
                    <select name="type" class="form-control m-b" >
                        <option value="1" th:selected="${jiajiaHuoDong.type == 1}" >社工端</option>
                        <option value="2" th:selected="${jiajiaHuoDong.type == 2}">用户端</option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">图片(建议长宽 700*240)：</label>
                <div class="col-sm-8">
                    <div class="file-loading">
                        <input id="file" class="form-control" accept="image/jpg,image/jpeg,image/png" name="file"  type="file">
                        <img th:src="*{photo}" style="width: 80px ;height: auto;" src="" id="imgPhoto"  />
                        <input th:field="*{photo}"  id="photo" class="form-control" name="photo"   type="text" style="display:none">
                    </div>

                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">跳转地址：</label>
                <div class="col-sm-8">
                    <input name="url" th:field="*{url}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">是否展示：</label>
                <div class="col-sm-8">
                    <select name="isShow" class="form-control m-b">
                        <option value="0" th:selected="${jiajiaHuoDong.isShow == 0}">否</option>
                        <option value="1" th:selected="${jiajiaHuoDong.isShow == 1}">是</option>
                    </select>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "jiajia/huoDong";
        $("#form-huoDong-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-huoDong-edit').serialize());
            }
        }

        function uploadFile(idSelector,callback) {
            var formData = new FormData();
            formData.append('file',$(idSelector)[0].files[0]);
            $.modal.loading("图片上传中，请稍后...")
            $.ajax({
                url: "/common/admin/upload/up/single",
                data: formData,
                type: "post",
                dataType: "json",
                processData: false,
                contentType: false,
                success: function(result) {
                    $.modal.closeLoading();
                    callback(result)
                }
            })
        }

        $("#file").bind('change', function () {
            $("#imgPhoto").show();
            $("#imgPhoto").attr("src",URL.createObjectURL($(this)[0].files[0]));

            uploadFile("#file",function (res1) {
                $("#photo").val(res1.url);

            })
        });


    </script>
</body>
</html>